package com.fira.edu.service.impl;

import java.util.List;
import com.fira.common.utils.DateUtils;
import com.fira.common.utils.uuid.IdUtils;
import com.fira.edu.domain.dto.StudentCourseListDTO;
import com.fira.edu.domain.dto.StudentRollCallCountDTO;
import com.fira.edu.domain.vo.RenewNoticeListVO;
import com.fira.edu.domain.vo.StudentCourseListVO;
import com.fira.edu.domain.vo.StudentCourseRollCallVO;
import com.fira.edu.domain.vo.StudentRollCallCountVO;
import com.fira.edu.mapper.EduClassRollCallMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fira.edu.mapper.EduStudentCourseMapper;
import com.fira.edu.domain.EduStudentCourse;
import com.fira.edu.service.IEduStudentCourseService;
import com.fira.common.core.text.Convert;

/**
 * 学生课时信息Service业务层处理
 * 
 * @author wuzhenggui
 * @date 2021-10-11
 */
@Service
public class EduStudentCourseServiceImpl implements IEduStudentCourseService 
{
    @Autowired
    private EduStudentCourseMapper eduStudentCourseMapper;
    @Autowired
    private EduClassRollCallMapper eduClassRollCallMapper;

    /**
     * 查询学生课时信息
     * 
     * @param id 学生课时信息ID
     * @return 学生课时信息
     */
    @Override
    public EduStudentCourse selectEduStudentCourseById(String id)
    {
        return eduStudentCourseMapper.selectEduStudentCourseById(id);
    }

    /**
     * 查询学生课时信息列表
     * 
     * @param eduStudentCourse 学生课时信息
     * @return 学生课时信息
     */
    @Override
    public List<EduStudentCourse> selectEduStudentCourseList(EduStudentCourse eduStudentCourse)
    {
        return eduStudentCourseMapper.selectEduStudentCourseList(eduStudentCourse);
    }

    /**
     * 新增学生课时信息
     * 
     * @param eduStudentCourse 学生课时信息
     * @return 结果
     */
    @Override
    public int insertEduStudentCourse(EduStudentCourse eduStudentCourse)
    {
        eduStudentCourse.setId(IdUtils.fastSimpleUUID());
        eduStudentCourse.setCreateTime(DateUtils.getNowDate());
        return eduStudentCourseMapper.insertEduStudentCourse(eduStudentCourse);
    }

    /**
     * 修改学生课时信息
     * 
     * @param eduStudentCourse 学生课时信息
     * @return 结果
     */
    @Override
    public int updateEduStudentCourse(EduStudentCourse eduStudentCourse)
    {
        eduStudentCourse.setUpdateTime(DateUtils.getNowDate());
        return eduStudentCourseMapper.updateEduStudentCourse(eduStudentCourse);
    }

    /**
     * 删除学生课时信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteEduStudentCourseByIds(String ids)
    {
        return eduStudentCourseMapper.deleteEduStudentCourseByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除学生课时信息信息
     * 
     * @param id 学生课时信息ID
     * @return 结果
     */
    @Override
    public int deleteEduStudentCourseById(String id)
    {
        return eduStudentCourseMapper.deleteEduStudentCourseById(id);
    }

    /**
     * 小程序-查询续费提醒列表
     *
     * @param tenantId
     * @return
     */
    @Override
    public List<RenewNoticeListVO> selectRenewNoticeList(String tenantId) {
        return eduStudentCourseMapper.selectRenewNoticeList(tenantId);
    }

    /**
     * 小程序-学员中心-学员课表列表
     *
     * @param studentCourseListDTO
     * @return
     */
    @Override
    public StudentCourseRollCallVO selectStudentCourseInfoList(StudentCourseListDTO studentCourseListDTO) {
        //查询已上课表
        studentCourseListDTO.setType("1");
        List<StudentCourseListVO> studentCourseListVOList = eduStudentCourseMapper.selectStudentCourseInfoList(studentCourseListDTO);
        //查询周课表
        studentCourseListDTO.setType("0");
        List<StudentCourseListVO> weekStudentCourseListVOList = eduStudentCourseMapper.selectStudentCourseInfoList(studentCourseListDTO);


        StudentRollCallCountVO studentRollCallCountVO = new StudentRollCallCountVO();
        StudentRollCallCountDTO studentRollCallCountDTO = new StudentRollCallCountDTO();
        studentRollCallCountDTO.setStudentId(studentCourseListDTO.getStudentId());
        studentRollCallCountDTO.setToClassStatus("到课");
        Integer toClass = eduClassRollCallMapper.selectStudentRollCallCount(studentRollCallCountDTO);
        studentRollCallCountDTO.setToClassStatus("迟到");
        Integer lateClass = eduClassRollCallMapper.selectStudentRollCallCount(studentRollCallCountDTO);
        studentRollCallCountDTO.setToClassStatus("缺席");
        Integer absentClass = eduClassRollCallMapper.selectStudentRollCallCount(studentRollCallCountDTO);
        studentRollCallCountDTO.setToClassStatus("补课");
        Integer lessonsClass = eduClassRollCallMapper.selectStudentRollCallCount(studentRollCallCountDTO);
        studentRollCallCountVO.setToClass(toClass);
        studentRollCallCountVO.setLateClass(lateClass);
        studentRollCallCountVO.setAbsentClass(absentClass);
        studentRollCallCountVO.setLessonsClass(lessonsClass);

        StudentCourseRollCallVO studentCourseRollCallVO = new StudentCourseRollCallVO();
        studentCourseRollCallVO.setStudentCourseListVOList(studentCourseListVOList);
        studentCourseRollCallVO.setWeekStudentCourseListVOList(weekStudentCourseListVOList);
        studentCourseRollCallVO.setStudentRollCallCountVO(studentRollCallCountVO);
        return studentCourseRollCallVO;
    }
}
